package thread;

public class Demo11 {
    public static void main(String[] args) throws InterruptedException{
        Thread t=new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    //throw new RuntimeException(e);
                    //这个线程翻桌了
                    //加上break就是终止
                    //啥都不就是不终止
                    //有其他逻辑，然后再break，就是稍后终止
                   // break;
                }
            }
            System.out.println("thread线程终止");
        });
        t.start();
        Thread.sleep(3000);
        System.out.println("main线程尝试终止t线程");
        t.interrupt();
        //main方法调用的，此时就是main
        //System.out.println("main:"+Thread.currentThread().getName());
    }
}
